XMLWriter write xml C#

45

XMLWriter write xml C# -

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
     XmlTextWriter writer = new XmlTextWriter("Shopping_list.xml", null);

     //Write the root element
     writer.WriteStartElement("The_list");

     //Write sub-elements
     writer.WriteElementString("Fruit", "Banana");
     writer.WriteElementString("Vegetable", "Carrot");
     writer.WriteElementString("Drink", "Water");

     // end the root element
     writer.WriteEndElement();

     //Write the XML to file and close the writer
     writer.Close();
  }
}

Comments

Submit
0 Comments